package com.test.spring.util.config;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configurable
@Component
public class ThreadPoolExecutorConfig {

    @Bean
    @Primary
    public ExecutorService threadPoolTaskExecutor() {
        ExecutorService executorService = new ThreadPoolExecutor(
                120,
                120,
                10,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(1024),
                new ThreadPoolExecutor.CallerRunsPolicy());

        return executorService;
    }
}
